<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Redis;
use App\Models\Shop;
use App\Models\ShopEnvelop;
use App\Services\TencentMap;
use App\Services\RedisService;
use App\Repos\UserRepo;
use App\Repos\ShopRepo;
use App\Repos\OrderRepo;
use App\Repos\ShopRechargeRepo;
use App\Repos\CouponRepo;
use Cache;
use Carbon\Carbon;
use EasyWeChat;
use App\Services\WechatTpl;

class IndexController extends Controller
{
    public function dashboard()
    {
        $userNum = UserRepo::count();
        //$shopNum = ShopRepo::count();
        $orderNum = OrderRepo::orderCount();
        $totalAmount= OrderRepo::orderAmount();
        return view('admin.dashboard',compact('userNum','orderNum','totalAmount'));
    }

    public function index()
    {
    	$data['shop_id'] = 55;
       
        $data['money']   = 10000; //分
        $data['source']  = 2; 
        $order = ShopRechargeRepo::create($data);
        $data['recharge_id'] = $order->id;
        $data['shop_id']     = $order->shop_id;
        $data['money']       = $order->money;           
        ShopRechargeRepo::createEnvelop($data);
        // $msg['openid']      = 'ob-tN5aq6XwEWJz1-DYSrsMJEYfM';
        // $msg['template_id'] = 'OAw7aUUSgI54cBIML2Mb9lq0TkQiooKVAizFN8IVlnU';
        // $msg['form_id']     = '1553212603973';
        // $msg['data'] =  [
        //                 'keyword1' => '测试商户',
        //                 'keyword2' => '201903220756133491',
        //                 'keyword3' => '2019-03-22 08：30',
        //                 'keyword4' => '大香蕉',
        //                 'keyword5' => '10元',
        //                 'keyword6' => '库存不足',
        //                 // ...
        //                 ];
        // $rs = WechatTpl::sendTplMsg('order_cancle',$msg);
        // dd($rs);
        // $keys = Redis::keys('*');
      
        // Redis::del('fruit:shops');
        //dd(Redis::get('name'));
       // $shops_types = Redis::type('shops');
        //$shops = Redis::zrange('shops',0,-1);
        //dd($keys,$shops_types,$shops);
        //Redis::set('name', 'Taylor');
    	//$user = Redis::get('name');
    	


    	
    	// $items = Redis::georadius("fruit:shops:geo", '120.429533', '36.177618', 5000, "m", "WITHDIST", "ASC");
    	// dd($items);

        //$rs= TencentMap::coordiateToAddress('36.173867,120.427149');
        //dd($rs);
    }

    public function test()
    {
        $data['shop_id'] = 55;

        $one = CouponRepo::randomOne($data);
        dd($one);
        $data['money']   = 10000; //分
        $data['source']  = 2; 
        $data['code'] = date('YmdHis');
        $order = ShopRechargeRepo::create($data);

        $data['recharge_id'] = 1;
        $data['shop_id']     = 55;
        $data['money']       = 10000;           
        ShopRechargeRepo::createEnvelop($data);

        // $data['user_id'] = 1;
        //$data['money']   = 88;
        //$openid          = 'ob-tN5epRY6YIdxw3gIog_5OzmQE';
        //$rs = WechatTpl::toBalance($data,$openid);
        //dd($rs);
        

    }
}
